home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / networking / otpapsampleserver / enableeomsample.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  2.3 KB  |  82 lines

  1. /*
  2.     File: EnableIPReuseAddrSample.c
  3.     By:        Rich Kubota
  4.             Developer Technical Support
  5.     
  6.     Purpose: Demonstrate the use of the OTOptionManagement call to tell a PAP or
  7.             ADSP endpoint to enable/disable the EOM option.
  8.             
  9.             Note that this sample does not support asynch endpoints.  To support
  10.             an asynch endpoint, the same call to OTOptionManagement would happen
  11.             however, the endpoint handler will be called with the
  12.             T_OPTMGMTCOMPLETE event.  The handler would then inspect the cookie, 
  13.             which will be the TOptMgmt "ret" value to check for the
  14.             success or failure of the call.
  15.             
  16. */
  17.  
  18. #include "OpenTransport.h"            // open transport files            
  19. #include "OpenTptAppletalk.h"
  20.  
  21. extern OSStatus DoNegotiateEOMOption(EndpointRef ep, Boolean enableEOM);
  22.  
  23. /*
  24.     Sample function to enable/disable the EOM option for 
  25.     ADSP.  This function also demonstrates the
  26.     use of the OTOptionManagement call.
  27.     
  28.     Unless explicitely defined by XTI, all Open Transport options
  29.     use a kOTFourByteOptionSize buffer.
  30.     
  31.     Input
  32.     EndpointRef ep - endpoint on which to set EOM option on
  33.     Boolean enableEOM - true - option on, false - option off
  34.  
  35.    Return: kOTNoError indicates that the option was successfully negotiated
  36.                OSStatus is an error if < 0, otherwise, the status field is
  37.                returned and is > 0.
  38.     
  39. */
  40. OSStatus DoNegotiateEOMOption(EndpointRef ep, Boolean enableEOM)
  41.  
  42. {
  43.     UInt8        buf[kOTFourByteOptionSize];    // define buffer for fourByte Option size
  44.     TOption*    opt;                        // option ptr to make items easier to access
  45.     TOptMgmt    req;
  46.     TOptMgmt    ret;
  47.     OSStatus    err;
  48.     
  49.     if (OTIsSynchronous(ep) == false)            // check whether ep sync or not
  50.     {
  51.         DebugStr("\pThis routine does not support asynch endpoints");
  52.         return (OSStatus)-1;
  53.     }
  54.                 
  55.     opt = (TOption*)buf;                    // set option ptr to buffer
  56.     req.opt.buf    = buf;
  57.     req.opt.len    = sizeof(buf);
  58.     req.flags    = T_NEGOTIATE;                // negotiate for EOM option
  59.  
  60.     ret.opt.buf = buf;
  61.     ret.opt.maxlen = kOTFourByteOptionSize;
  62.     
  63.     opt->level    = ATK_PAP;                    // dealing with PAP
  64.     opt->name    = OPT_ENABLEEOM;
  65.     opt->len    = kOTFourByteOptionSize;
  66.     opt->status = 0;
  67.     *(UInt32*)opt->value = enableEOM;        // set the desired option level, true or false
  68.  
  69.     err = OTOptionManagement(ep, &req, &ret);
  70.     
  71.         // if no error then return the option status value
  72.     if (err == kOTNoError)
  73.     {
  74.         if (opt->status != T_SUCCESS)
  75.             err = opt->status;
  76.         else
  77.             err = kOTNoError;
  78.     }
  79.         
  80.     return err;
  81. }
  82.